<template>
	<view>
		<input class="uni-input" v-model="form.name" focus placeholder="名字" />
		<input class="uni-input" v-model="form.companyName" focus placeholder="公司名" />
		<image v-if="form.img" :src="form.img"></image>
		<button type="default" @click="upload">文件上传</button>
		<button type="default" @click="submite">确定</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{
					name:'兜里反',
					companyName:'迅雷',
					img:'../../static/头像1.png'
				}

			}
		},
		methods: {
			upload(){
				uni.chooseImage({
				    success: (chooseImageRes) => {
				        const tempFilePaths = chooseImageRes.tempFilePaths;
				        uni.uploadFile({
				            url: '/api/uploadfile', //仅为示例，非真实的接口地址
				            filePath: tempFilePaths[0],
				            name: 'file',
				            formData: {
				                'user': 'test'
				            },
				            success: (uploadFileRes) => {
				                console.log(uploadFileRes.data);
								this.form.img = uploadFileRes.data
				            }
				        });
				    }
				});
			},
			

			submite(){
				console.log(this.name)
				console.log(this.companyName)
				uni.request({
					url: '/api/hello/add',
					method:'POST',
					data:this.form,
					success: (res) => {
						uni.switchTab({
						    url: '/pages/addressList/addressList'
						});
						// this.datas = res.data
					}
				});
			}
		}
	}
</script>

<style>

</style>
